// pagesMer/pages/orderCoupon/detail/index.js
var app = getApp(), fetchApi = require("../../../../utils/httpPost.js"),
common_Js = require("../../../../component/common.js")
Page({

  /**
   * 页面的初始数据
   */
  data: {
    coupon:{},
    coupon_id:0,
    isLoading:true,
    netWork:false,
    verifyRecordList:[],
    reservationRecordList:[],
    isShowPopupVerifyRecord:false,
    isShowPopupReservationRecord:false,
    reservationList:[],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    if(options.id){
      this.data.coupon_id = parseInt(options.id)
    }
    this.onHttpInit();
  },

  /**
   * 获取页面数据的 http请求
   */
  onHttpInit: function (state) {
    var that = this
    fetchApi.httpPost('/product/order/coupon/detail', {
      coupon_id: that.data.coupon_id,
    }, function (res) {
      if (res.data.code == 0) {
        that.data.coupon = res.data.data.coupon;
        that.setData({
          coupon: res.data.data.coupon,
          reservationList: res.data.data.reservationList,
        })
      }
      that.onHttpVerifyRecord();
      that.onHttpReservationRecord();
      wx.stopPullDownRefresh() //停止下拉刷新
      that.setData({
         isLoading: false, loading: true, netWork: true,
      })
    }, function (res) {
        that.setData({ hasData: false,  isLoading: false,  loading: true, netWork: true })
    })
    wx.hideNavigationBarLoading() //完成停止加载
    wx.stopPullDownRefresh() //停止下拉刷新
  },
  /**
   * 获取页面数据的 http请求
   */
  onHttpVerifyRecord: function () {
    var that = this;
    fetchApi.httpPost('/product/order/coupon/verify/record', {
      order_coupon_id: that.data.coupon_id,
    }, function (res) {
      if (res.data.code == 0) {
        that.setData({
          verifyRecordList: res.data.data.verifies
        })
      }
      wx.stopPullDownRefresh() //停止下拉刷新
      that.setData({
         isLoading: false, loading: true, netWork: true,
      })
    }, function (res) {
        that.setData({ hasData: false,  isLoading: false,  loading: true, netWork: true })
    })
    wx.hideNavigationBarLoading() //完成停止加载
    wx.stopPullDownRefresh() //停止下拉刷新
  },
  /**
   * 获取页面数据的 http请求
   */
  onHttpReservationRecord: function () {
    var that = this;
    fetchApi.httpPost('/product/order/coupon/reservation/record', {
      coupon_id: that.data.coupon_id,
    }, function (res) {
      if (res.data.code == 0) {
        that.setData({
          reservationRecordList: res.data.data.records
        })
      }
      wx.stopPullDownRefresh() //停止下拉刷新
      that.setData({
         isLoading: false, loading: true, netWork: true,
      })
    }, function (res) {
        that.setData({ hasData: false,  isLoading: false,  loading: true, netWork: true })
    })
    wx.hideNavigationBarLoading() //完成停止加载
    wx.stopPullDownRefresh() //停止下拉刷新
  },
  verifyRecord(){
    this.setData({
      isShowPopupVerifyRecord: !this.data.isShowPopupVerifyRecord,
    })
  },
  showRecord(){
    this.setData({
      isShowPopupVerifyRecord: !this.data.isShowPopupVerifyRecord,
    })
  },
  showReservationRecord(){
    this.setData({
      isShowPopupReservationRecord: !this.data.isShowPopupReservationRecord,
    })
  },
  goYuyue(){
    wx.navigateTo({
      url: '../reservation/index?id=' + this.data.coupon_id,
    })
  }
})